/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bbchess.units.pieces;

import bbchess.units.ChessPiece;
import bbchess.units.ChessSquare;
import bbchess.util.ImageLoader;

/**
 *
 * @author Tyler
 */
public class Knight extends ChessPiece {
    public Knight(String color, ChessSquare position) {
        initPiece(color, position);
        setUnit("N");

        if (color.equals("black")) {
            setSprite(ImageLoader.getbKnightImage());
        } else {
            setSprite(ImageLoader.getwKnightImage());
        }
    }

    @Override
    public void calculateLegalMoves() {
        addLegalMoves(board.calculatePath(getPosition().getPosition(), 1, 1, 2, false));
        addLegalMoves(board.calculatePath(getPosition().getPosition(), 1, 1, -2, false));
        addLegalMoves(board.calculatePath(getPosition().getPosition(), 1, -1, 2, false));
        addLegalMoves(board.calculatePath(getPosition().getPosition(), 1, -1, -2, false));
        addLegalMoves(board.calculatePath(getPosition().getPosition(), 1, 2, 1, false));
        addLegalMoves(board.calculatePath(getPosition().getPosition(), 1, 2, -1, false));
        addLegalMoves(board.calculatePath(getPosition().getPosition(), 1, -2, 1, false));
        addLegalMoves(board.calculatePath(getPosition().getPosition(), 1, -2, -1, false));
    }

    @Override
    public void calculateCaptureMoves() {
        addCapturableMove(board.calculateCapture(getPosition().getPosition(), getColor(), 1, 1, 2));
        addCapturableMove(board.calculateCapture(getPosition().getPosition(), getColor(), 1, 1, -2));
        addCapturableMove(board.calculateCapture(getPosition().getPosition(), getColor(), 1, -1, 2));
        addCapturableMove(board.calculateCapture(getPosition().getPosition(), getColor(), 1, -1, -2));
        addCapturableMove(board.calculateCapture(getPosition().getPosition(), getColor(), 1, 2, 1));
        addCapturableMove(board.calculateCapture(getPosition().getPosition(), getColor(), 1, 2, -1));
        addCapturableMove(board.calculateCapture(getPosition().getPosition(), getColor(), 1, -2, 1));
        addCapturableMove(board.calculateCapture(getPosition().getPosition(), getColor(), 1, -2, -1));
    }

    @Override
    public void calculateThreatenedMoves() {
        addThreatenedMoves(board.calculatePath(getPosition().getPosition(), 1, 1, 2, true));
        addThreatenedMoves(board.calculatePath(getPosition().getPosition(), 1, 1, -2, true));
        addThreatenedMoves(board.calculatePath(getPosition().getPosition(), 1, -1, 2, true));
        addThreatenedMoves(board.calculatePath(getPosition().getPosition(), 1, -1, -2, true));
        addThreatenedMoves(board.calculatePath(getPosition().getPosition(), 1, 2, 1, true));
        addThreatenedMoves(board.calculatePath(getPosition().getPosition(), 1, 2, -1, true));
        addThreatenedMoves(board.calculatePath(getPosition().getPosition(), 1, -2, 1, true));
        addThreatenedMoves(board.calculatePath(getPosition().getPosition(), 1, -2, -1, true));
    }
}
